<?php
namespace App\Service\ApiQd;

use Illuminate\Support\Facades\DB;

class IncomeService extends BaseService
{
//    /**
//     * 可用列表
//     * @param array $pages【start，limit】
//     * @return array
//     */
//    public function getList($pages, $uid)
//    {
//        $start = ($pages['start'] - 1) * $pages['limit'];
//        $db = $this->dbwbConn($this->dbDistributorIncome)->where('del', 0)->where('uid', $uid);
//        $total = $db->count();
//        $res = $db->skip($start)->take($pages['limit'])
//            ->orderBy('id', 'desc')
//            ->get()
//            ->map(function ($value){
//                return (array)$value;
//            })
//            ->toArray();
//        if (!count($res)) {
//            return array('code' => 0, 'msg' => '没有数据', 'data' => [], 'total' => 0);
//        }
//        return array('code' => 0, 'msg' => 'success', 'data' => $res, 'total' => $total);
//    }

    /**
     * 可用列表
     * @param array $pages【start，limit】
     * @return array
     */
    public function getList($pages, $uid)
    {
        $start = ($pages['start'] - 1) * $pages['limit'];
        $db = $this->dbwbConn($this->dbDistributorIncome)
            ->where('del', 0)->where('uid', $uid);
        $total = $db->count();
        $res = $db->skip($start)->take($pages['limit'])
            ->orderBy('id', 'desc')
            ->get();
        if (!count($res)) {
            return $this->toback(0, '没有数据');
        }
        $arys = [];
        foreach ($res as $v) {
            $v = (array) $v;
            $arys[] = [
                'id' => $v['id'],
                'uid' => $v['uid'],
                'orderno' => $v['orderno'],
                'ordertime' => $v['ordertime'],
                'amount' => toNumber($v['amount']),
                'status' => $v['status'],
                'addtime' => $v['addtime'],
                'del' => $v['del'],
            ];
        }
        return $this->toback(0, '', $arys, $total);
    }
}